﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Wolf Lai
 *      Date:           2013/5/28 星期二 21:10:50
 *      Version:        
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Sector7.Medical.EntityType;
using Sector7.Framework.DB;
using Sector7.Medical.Consts;

namespace Sector7.Medical.DAO.Standard
{
    /// <summary>
    /// 采购单数据访问接口
    /// </summary>
    public class PurchasesBillDAO : DAOBase<M7_PurchasesBill>, IPurchasesBillDAO
    {
        #region Public functions
        public override object Create(M7_PurchasesBill bill)
        {
            string sql = string.Format(@"
                INSERT INTO {0}
                        ({1} ,{2} ,{3} ,{4} ,{5} ,{6} ,{7} ,{8} ,{9} ,{10} ,{11} ,{12} ,{13} ,{14})
                    VALUES
                        (@{1} ,@{2} ,@{3} ,@{4} ,@{5} ,@{6} ,@{7} ,@{8} ,@{9} ,@{10} ,@{11} ,@{12} ,@{13}, @{14})",
                C_M7_TableName.PURCHASES_BILL,
                C_ColumnName.BILL_ID,
                C_ColumnName.BILL_DATE,
                C_ColumnName.RECORD_TIME,
                C_ColumnName.VENDOR_ID,
                C_ColumnName.OPERATOR_ID,
                C_ColumnName.CHECKER_ID,
                C_ColumnName.BUYER_ID,
                C_ColumnName.BOOK_KEEPER_ID,
                C_ColumnName.STORE_KEEPER_ID,
                C_ColumnName.BILL_AMOUNT,
                C_ColumnName.PAY_AMOUNT,
                C_ColumnName.DEPT_ID,
                C_ColumnName.PAYMENT_TYPE,
                C_ColumnName.REMARKS);

            using (DBHelper helper = new DBHelper())
            {
                return helper.ExecuteNonQuery(sql,
                    DBUtil.CreateSqlParameter(bill.BillId, C_ColumnName.BILL_ID),
                    DBUtil.CreateSqlParameter(bill.BillDate, C_ColumnName.BILL_DATE),
                    DBUtil.CreateSqlParameter(bill.RecordTime, C_ColumnName.RECORD_TIME),
                    DBUtil.CreateSqlParameter(bill.VendorId, C_ColumnName.VENDOR_ID),
                    DBUtil.CreateSqlParameter(bill.OperatorId, C_ColumnName.OPERATOR_ID),
                    DBUtil.CreateSqlParameter(bill.CheckerId, C_ColumnName.CHECKER_ID),
                    DBUtil.CreateSqlParameter(bill.BuyerId, C_ColumnName.BUYER_ID),
                    DBUtil.CreateSqlParameter(bill.BookKeeperId, C_ColumnName.BOOK_KEEPER_ID),
                    DBUtil.CreateSqlParameter(bill.StoreKeeperId, C_ColumnName.STORE_KEEPER_ID),
                    DBUtil.CreateSqlParameter(bill.BillAmount, C_ColumnName.BILL_AMOUNT),
                    DBUtil.CreateSqlParameter(bill.PayAmount, C_ColumnName.PAY_AMOUNT),
                    DBUtil.CreateSqlParameter(bill.DeptId, C_ColumnName.DEPT_ID),
                    DBUtil.CreateSqlParameter(bill.PaymentType, C_ColumnName.PAYMENT_TYPE),
                    DBUtil.CreateSqlParameter(bill.Remarks, C_ColumnName.REMARKS));
            }
        }
        #endregion

        #region Structure
        public PurchasesBillDAO()
        {
            m_tableName = C_M7_TableName.PURCHASES_BILL;
            m_primaryKeyName = C_ColumnName.BILL_ID;
        }
        #endregion
    }
}
